package com.itheima.homework.homework08;

import java.util.ArrayList;

public class Demo8 {
    public static void main(String[] args) {
        ArrayList<Employee> arrayList = new ArrayList<>();
        Employee e1 = new Employee("张三", 23);
        Employee e2 = new Employee("李四", 24);
        Employee e3 = new Employee("张三", 23);
        Employee e4 = new Employee("张三", 28);

        arrayList.add(e1);
        arrayList.add(e2);
        arrayList.add(e3);
        arrayList.add(e4);

        //循环嵌套,完成缘分匹配
        for (int i = 0; i < arrayList.size(); i++) {
            //定义一个标记,默认集合中没人跟当前元素有缘
            boolean flag = false;

            //遍历集合,如果集合中存在和当前元素相同属性的值,就修改flag
            for (int j = 0; j < arrayList.size(); j++) {
                //当且仅当地址值不同且属性值相同时,修改flag为true
                if (arrayList.get(i) != arrayList.get(j) && arrayList.get(i).equals(arrayList.get(j))) {
                    flag = true;
                }
            }

            if (flag) {
                System.out.println(arrayList.get(i).toString() + "获得了缘分大礼包");
            } else {
                System.out.println(arrayList.get(i).toString() + "获得了普通大礼包");
            }
        }
    }
}
